<%--
    Document   : update
    Created on : Jul 1, 2012, 12:30:17 AM
    Author     : aspr0
--%>


<%@page import="is.model.dao.EmployeeDao"%>
<%@page import="is.interfaces.Dao"%>
<%@page import="is.model.exceptions.ObjectNotFoundException"%>
<%@page import="is.web.GetParam"%>
<%@page import="java.sql.SQLException"%>
<%@page import="is.model.exceptions.DeletingLinkedObjectException"%>
<%@page import="is.model.Restriction"%>
<%@page import="is.model.bean.Employee"%>
<%@page import="is.model.DataSource"%>
<%@page import="is.model.bean.Employee"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
    request.setCharacterEncoding(is.Conf.ENCODING); // !!!

    Integer id = null;

    try
    {
        id = Integer.parseInt(request.getParameter("id"));
    }
    catch ( NumberFormatException e )
    {
        response.sendRedirect(".");
        return; // after responce set execution no more!
    }

    Employee employee = null;
    DataSource.establishConnection();
    Dao<Employee> employeeDao = new EmployeeDao();

    try
    {
        Employee initialEmployee = new Employee();
        initialEmployee.setId(id);
        employeeDao.setInitialBean(initialEmployee);
        employeeDao.objectExists();
        employee = employeeDao.retrieve();

        if (request.getMethod().equals("POST"))
        {
            employeeDao.delete();
            response.sendRedirect("?"+GetParam.INFO+"=1");
            return;
        }

    }
    catch (ObjectNotFoundException e)
    {
        response.sendRedirect(".");
        return;
    }
    catch (SQLException e)
    {
        e.printStackTrace();
        response.sendRedirect("?e=0");
        return;
    }
    catch (NumberFormatException e)
    {
        response.sendRedirect("?w=0");
        return;
    }


    DataSource.closeConnection();
%>

<jsp:include page="../template/delete.jsp">
    <jsp:param name="datatype" value="<%=employee.getTableName()%>"/>
    <jsp:param name="beanName" value="<%=employee.getFirstName()+" "+employee.getLastName()%>"/>
</jsp:include>